package com.goldsprite.infinityworld.screens.examples.ui;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ScreenUtils;
import com.goldsprite.gdxcore.screens.GScreen;

public class WindowExampleScreen extends GScreen {
	public static float WORLD_WIDTH = 960;
	public static float WORLD_HEIGHT = 540;
	private OrthographicCamera cam;
	private Window window;
	private Stage stage;
	private Skin skin;


	@Override
	public void create() {
		WORLD_WIDTH = getViewport().getWorldWidth();
		WORLD_HEIGHT = getViewport().getWorldHeight();

		//skin = GlobalAssets.instance.defaultSkin;
		String skinPath = "ui_skins/shade/skin/uiskin.json";
		skin = new Skin(Gdx.files.internal(skinPath));

		stage = new Stage(getViewport());
		getImp().addProcessor(stage);

		createWindow();

		stage.addActor(window);
	}

	private void createWindow() {
		// 创建窗口，设置标题，皮肤，bounds，可拖动与重大小
		window = new Window("MyWindow", skin);
		window.setSize(420, 300);
		window.setPosition(WORLD_WIDTH / 2, WORLD_HEIGHT / 2, Align.center);
		window.setMovable(true);
		window.setResizable(true);

		// 调用添加内容的方法
		addWindowContent();
	}

	private void addWindowContent() {
		// 创建按钮容器
		Table buttonTable = new Table();
		TextButton button1 = new TextButton("menu1", skin);
		TextButton button2 = new TextButton("menu1", skin);
		TextButton button3 = new TextButton("menu3", skin);
		buttonTable.add(button1).pad(5);
		buttonTable.add(button2).pad(5);
		buttonTable.add(button3).pad(5);
		buttonTable.row();

		// 创建文本区域和滑动布局
		TextArea textArea = new TextArea("This is a scrollable text area.", skin);
		ScrollPane scrollPane = new ScrollPane(textArea, skin);
		scrollPane.setFadeScrollBars(false);
		scrollPane.setScrollingDisabled(true, false); // 水平禁用滚动，垂直允许滚动

		// 将内容添加到窗口
		window.add(buttonTable).growX().pad(5);
		window.row(); // 换行
		window.add(scrollPane).grow().pad(5);

		// 紧凑布局
		//window.pack();
	}


	@Override
	public void render(float delta) {
		ScreenUtils.clear(0.8f, 0.6f, 0.6f, 1);

		//更新与绘制舞台内容
		stage.act(delta);
		stage.draw();
	}

}
